import 'dart:io';
import 'dart:typed_data';

import 'package:flutter_image_compress/flutter_image_compress.dart';
import 'package:flutter_native_image/flutter_native_image.dart';
import 'package:wechat_assets_picker/wechat_assets_picker.dart';
import 'package:path_provider/path_provider.dart';
import 'package:video_compress/video_compress.dart';

class Util {
  static Future<File?> nativeCompress(String filePath) async {
    File compressedFile =
        await FlutterNativeImage.compressImage(filePath, quality: 70);
    return compressedFile;
  }

  // 2. compress file and get file.
  static Future<File?> compressAndGetFile(String filePath) async {
    //临时目录
    var dir = await getTemporaryDirectory();
    var targetPath = dir.absolute.path + "/temp.jpg";
    var result = await FlutterImageCompress.compressAndGetFile(
      filePath,
      targetPath,
      quality: 60,
    );
    print(result!.lengthSync());
    return result;
  }

// 4. compress Uint8List and get another Uint8List.
  static Future<Uint8List> compressListAndGetList(Uint8List list) async {
    var result = await FlutterImageCompress.compressWithList(
      list,
      quality: 60,
    );
    print(list.length);
    print(result.length);
    return result;
  }

  static Future<File?> compressVido(String path) async {
    MediaInfo? mediaInfo = await VideoCompress.compressVideo(
      path,
      quality: VideoQuality.DefaultQuality,
      deleteOrigin: true, // It's false by default
    );
    return mediaInfo!.file;
  }
}
